package com.jd.myaaaccount.util;
 
import java.util.HashMap;

import android.graphics.Bitmap;
import android.util.Log;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;


public class QRCodeHelper {
	private static final int BLACK = 0xff000000;

	public static Bitmap getQRCode(String uri, int QR_WIDTH, int QR_HEIGHT) {
		Log.e("veri", "inkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk1111");

		try {
			Log.e("veri", "inkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk2222");
			HashMap<com.google.zxing.EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
			hints.put(com.google.zxing.EncodeHintType.CHARACTER_SET, "utf-8");
			hints.put(com.google.zxing.EncodeHintType.ERROR_CORRECTION,
					ErrorCorrectionLevel.H);
			BitMatrix matrix = new QRCodeWriter().encode(uri,
					BarcodeFormat.QR_CODE, QR_WIDTH, QR_HEIGHT, hints);
			int w = matrix.getWidth();
			int h = matrix.getHeight();
			int[] pixels = new int[w * h];
			for (int y = 0; y < h; y++) {
				for (int x = 0; x < w; x++) {
					if (matrix.get(x, y)) {
						pixels[y * w + x] = BLACK;
					}
				}
			}
			Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
			bmp.setPixels(pixels, 0, w, 0, 0, w, h);
			return bmp;
			// return null;
		} catch (WriterException e) {
			e.printStackTrace();
			return null;
		}
	}
}
